//
//  DrawRecordCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/8/28.
//

import UIKit

class DrawRecordCell: UITableViewCell {
    
    lazy var costLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 13)
        label.textColor = .init(named: "gray_666666")
        return label
    }()
        
    lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .regular, size: 12)
        label.textColor = .init(named: "gray_999999")
        return label
    }()
    
    lazy var getLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .right
        label.font = .wn_font(name: .bold, size: 16)
        label.textColor = .init(named: "red_FE95B4")
        return label
    }()
    
    lazy var goldImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "reward_coin"))
        return image
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .init(named: "gray_D0D0D0")
        return view
    }()
    
    var model: LotteryModel? {
        didSet {
            if let m = model {
                timeLabel.text = m.time?.wn_toJavaDetailDate()
                costLabel.text = "花費 \(m.cost) 金幣"
                getLabel.text = "+\(m.gold)"
            }
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .white
        contentView.addSubview(costLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(getLabel)
        contentView.addSubview(goldImage)
        contentView.addSubview(lineView)
        costLabel.snp.makeConstraints { (make) in
            make.top.equalTo(12)
            make.left.equalTo(12)
        }
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(costLabel.snp.left)
            make.bottom.equalTo(-12)
        }
        getLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-12)
        }
        goldImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(getLabel.snp.left).offset(-6)
            make.size.equalTo(CGSize(width: 24, height: 24))
        }
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.bottom.right.equalTo(0)
            make.height.equalTo(0.5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
